package com.coin900.coin.base.utils;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

import java.io.IOException;

public class JavaSmsApi {

    /// Find your Account Sid and Token at twilio.com/user/account
    public static final String ACCOUNT_SID = "AC98f3212f5424c47520163996a6c7ab5d";
    public static final String AUTH_TOKEN = "0e9bc6ca8207263b1085afa63635096a";
    public static final String FROM_NUMBER = "+6582410003";

    /**
     * 智能匹配模板接口发短信
     *
     * @param text   　短信内容
     * @param mobile 　接受的手机号
     * @return json格式字符串
     * @throws IOException
     */
    public static void sendSms(String text,
                               String mobile) throws IOException {

        mobile = "+86" + mobile;

        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Message message = Message
                .creator(new PhoneNumber(mobile), new PhoneNumber(FROM_NUMBER),
                        "【tokenok.com】" + text)
                .create();
        System.out.println(message.getSid());

    }
}